/**
 * 
 */
package com.mobile2you.nci.android.domain;

import org.json.JSONException;
import org.json.JSONObject;

import android.graphics.Bitmap;

/**
 * @author JBromo
 * 
 */
public class Centres implements Comparable<Centres> {

	private String create;

	private String heading1;

	private String heading2;
	private int id;

	private int image;
	private String image1a;
	private String image1b;
	private double latitude;
	private double longitude;
	private String phone;
	private String texte;
	private String texte1;
	private String texte2;
	private String title;
	private String update;
	public double distance;
	private Bitmap bitmap;

	/**
	 * 
	 */
	public Centres() {
		super();
		// TODO Auto-generated constructor stub
	}

	public Centres(JSONObject object) throws JSONException {
		set(object);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Comparable#compareTo(java.lang.Object)
	 */
	@Override
	public int compareTo(Centres another) {
		if (title == null) {
			return 1;
		}
		return title.compareTo(another.title);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		Centres other = (Centres) obj;
		if (id != other.id) {
			return false;
		}
		if (Double.doubleToLongBits(latitude) != Double
				.doubleToLongBits(other.latitude)) {
			return false;
		}
		if (Double.doubleToLongBits(longitude) != Double
				.doubleToLongBits(other.longitude)) {
			return false;
		}
		if (title == null) {
			if (other.title != null) {
				return false;
			}
		} else if (!title.equals(other.title)) {
			return false;
		}
		return true;
	}

	/**
	 * @return the bitmap
	 */
	public Bitmap getBitmap() {
		return bitmap;
	}

	/**
	 * @return the create
	 */
	public String getCreate() {
		return create;
	}

	/**
	 * @return the distance
	 */
	public double getDistance() {
		return distance;
	}

	/**
	 * @return the heading1
	 */
	public String getHeading1() {
		return heading1;
	}

	/**
	 * @return the heading2
	 */
	public String getHeading2() {
		return heading2;
	}

	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}

	/**
	 * @return the image
	 */
	public int getImage() {
		return image;
	}

	/**
	 * @return the image1a
	 */
	public String getImage1a() {
		return image1a;
	}

	/**
	 * @return the image1b
	 */
	public String getImage1b() {
		return image1b;
	}

	public String getImageURL() {
		return "http://nci.m2y.fr/images/centres/" + image;
	}

	/**
	 * @return the latitude
	 */
	public double getLatitude() {
		return latitude;
	}

	/**
	 * @return the longitude
	 */
	public double getLongitude() {
		return longitude;
	}

	/**
	 * @return the phone
	 */
	public String getPhone() {
		return phone;
	}

	/**
	 * @return the texte
	 */
	public String getTexte() {
		return texte;
	}

	/**
	 * @return the texte1
	 */
	public String getTexte1() {
		return texte1;
	}

	/**
	 * @return the texte2
	 */
	public String getTexte2() {
		return texte2;
	}

	/**
	 * @return the title
	 */
	public String getTitle() {
		return title;
	}

	/**
	 * @return the update
	 */
	public String getUpdate() {
		return update;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		long temp;
		temp = Double.doubleToLongBits(latitude);
		result = prime * result + (int) (temp ^ temp >>> 32);
		temp = Double.doubleToLongBits(longitude);
		result = prime * result + (int) (temp ^ temp >>> 32);
		result = prime * result + (title == null ? 0 : title.hashCode());
		return result;
	}

	public void set(JSONObject object) throws JSONException {
		id = object.getInt("id");
		image = object.getInt("image");
		texte1 = object.getString("text1");
		texte2 = object.getString("text2");
		title = object.getString("title");
		latitude = object.getDouble("latitude");
		longitude = object.getDouble("longitude");
		phone = object.getString("phone");
		texte = object.getString("text");
		try {
			create = object.getString("created_at");
			heading1 = object.getString("heading1");
			heading2 = object.getString("heading2");

			image1a = object.getString("image1a");
			image1b = object.getString("image1b");

			update = object.getString("update_at");
		} catch (Exception e) {
			// TODO: handle exception
		}

	}

	/**
	 * @param bitmap
	 *            the bitmap to set
	 */
	public void setBitmap(Bitmap bitmap) {
		this.bitmap = bitmap;
	}

	/**
	 * @param create
	 *            the create to set
	 */
	public void setCreate(String create) {
		this.create = create;
	}

	/**
	 * @param distance
	 *            the distance to set
	 */
	public void setDistance(double distance) {
		this.distance = distance;
	}

	/**
	 * @param heading1
	 *            the heading1 to set
	 */
	public void setHeading1(String heading1) {
		this.heading1 = heading1;
	}

	/**
	 * @param heading2
	 *            the heading2 to set
	 */
	public void setHeading2(String heading2) {
		this.heading2 = heading2;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * @param image
	 *            the image to set
	 */
	public void setImage(int image) {
		this.image = image;
	}

	/**
	 * @param image1a
	 *            the image1a to set
	 */
	public void setImage1a(String image1a) {
		this.image1a = image1a;
	}

	/**
	 * @param image1b
	 *            the image1b to set
	 */
	public void setImage1b(String image1b) {
		this.image1b = image1b;
	}

	/**
	 * @param latitude
	 *            the latitude to set
	 */
	public void setLatitude(double latitude) {
		this.latitude = latitude;
	}

	/**
	 * @param longitude
	 *            the longitude to set
	 */
	public void setLongitude(double longitude) {
		this.longitude = longitude;
	}

	/**
	 * @param phone
	 *            the phone to set
	 */
	public void setPhone(String phone) {
		this.phone = phone;
	}

	/**
	 * @param texte
	 *            the texte to set
	 */
	public void setTexte(String texte) {
		this.texte = texte;
	}

	/**
	 * @param texte1
	 *            the texte1 to set
	 */
	public void setTexte1(String texte1) {
		this.texte1 = texte1;
	}

	/**
	 * @param texte2
	 *            the texte2 to set
	 */
	public void setTexte2(String texte2) {
		this.texte2 = texte2;
	}

	/**
	 * @param title
	 *            the title to set
	 */
	public void setTitle(String title) {
		this.title = title;
	}

	/**
	 * @param update
	 *            the update to set
	 */
	public void setUpdate(String update) {
		this.update = update;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "Centres [id=" + id + ", latitude=" + latitude + ", longitude="
				+ longitude + ", title=" + title + "]";
	}

}
